package cn.gson.springboot.controller;

import cn.gson.springboot.model.pojos.Employee;
import cn.gson.springboot.model.pojos.Function;
import cn.gson.springboot.model.pojos.FunctionType;
import cn.gson.springboot.model.service.FunctionTypeService;
import cn.gson.springboot.model.service.PrivilegeService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
public class PrivilegeController {
    @Autowired
    PrivilegeService ps;

    @RequestMapping("/login")
    @ResponseBody
    public String login(Employee emp, HttpSession session){
        Employee e = ps.findEmp(emp);
        System.out.println(e);
        if(e != null) {
            session.setAttribute("emp", e);
            return "success";
        }
        return "failed";
    }

    @RequestMapping("/logout")
    @ResponseBody
    public String logout( HttpSession session){
        session.invalidate();
        return "success";
    }
}
